<?php
//命名空间
namespace Shop\Controller;
//调用类库
use Shop\Controller\BaseController;
class IndexController extends BaseController {
	
	public function  _empty($name)          //_empty方法即空操作,当找不到请求的方法时,默认执行该方法,利用这个机制,我们可以实现错误页面和一些URL的优化。
	{
		echo "没有查到到".$name."操作";
	}
	
    public function index(){
		$this->view("index");
    }
    
    Public $pagename,$webtitle;
    
    
    //商品分类的商品列表
	public function proList(){
    	$cateID=I('get.cateid')?I('get.cateid'):0;
    	$currpage=I('get.page')?I('get.page'):1;
    	$perpage=I('get.perpage')?I('get.perpage'):3;
    	$orderby=I('get.orderby')?I('get.orderby'):'id';
    	$desca=I('get.desca')?I('get.desca'):'desc';
    	$showpageAll=5;
    	//D方法可以跨模块调用模型 递归当前分类下面的子类
    	$cateArray=D('Admin/category')->getCategory($cateID);
    	$catesubArray=array();
    	$catesubArray[]=$cateID;
    	foreach($cateArray as $catekey=>$cateValue)
    	{
    		$catesubArray[]=$cateValue['id'];
    	}
    	
    	
    	//标题--导航
    	$cateInfo=M('category')->where('id='.$cateID)->find();  //当前分类信息
		$parentArray=getParentCate($cateInfo['parent_id']);   //当前分类+当前分类的所有父类信息
    	$this->assign("parentArray",array_reverse($parentArray));//array_reverse() 函数将原数组中的元素顺序翻转
    	$this->assign("cateInfo",$cateInfo);
    	
    	//分页操作
    	$countRows=M("product")->where('category_id in('.join(',',$catesubArray).')')->count();
    	$pagedata=pages($currpage,$countRows,$perpage,$showpageAll);

    	
    	//商品分类信息--列表
    	$proList=M("product")->where('category_id in('.join(',',$catesubArray).')')->order("{$orderby} {$desca}")->limit($pagedata['offset'],$pagedata['perpage'])->select();
		
    	$this->assign("cateId",$cateID);
    	$this->assign("pagedata",$pagedata);
    	$this->assign("proList",$proList);
    	if($desca=='desc'){
    		$desca='asc';
    	}else{
    		$desca='desc';
    	}
    	$this->assign("pageTitle",$cateInfo['name']);
    	$this->assign("orderby",$orderby);
    	$this->assign("desca",$desca);
    	$this->view("list");
    }
    
    
    /*
     * 商品详情
     */
 	public function proDetail(){
    	$proid=I('get.proid');//获取商品id
        
        
        $this->webtitle='京东网';
    	
    	$proDetail=M("product")->where('id='.$proid)->find();
    	$proDes=M("product_des")->where('product_id='.$proDetail['id'])->find();
    	
    	$proDetail['des']=$proDes;
    	$this->assign("proDetail",$proDetail);
    	
    	//标题--导航
    	$parentArray=getParentCate($proDetail['category_id']);   //当前分类+当前分类的所有父类信息
    	$this->assign("parentArray",array_reverse($parentArray));//array_reverse() 函数将原数组中的元素顺序翻转---父类到子类的顺序
    	
        
        
        if(!empty($this->pagename))$this->webtitle=$this->pagename.'-'.$this->webtitle;
        $this->assign('webname',$this->webtitle);
        
    	
    	$this->view("detail");
    }
    
    
    public  function getComent()
    {
    
    }
    
    public function subComent()
    {
    
    }
    
    
    
    
    
}